<template>
  <view class="page">
    <view v-for="item in listData" :key="item.id" class="block">
      <image class="block__icon" src="~@/static/logo.png" />
      <view class="block__info">
        <text>车牌号码：<text class="yellow">{{item.number}}</text></text>
        <text class="text">车位编码：{{ item.code }}</text>
        <text class="text">入库时间：{{ item.startTime }}</text>
        <text class="text" v-if="item.note">备注：{{ item.note }}</text>
      </view>
      <image @click="deleteReservation(item)" class="block__delete" src="~@/static/my/delete.png" />
    </view>
    <view @tap="create" class="global-btn">添加新地址</view>
    <popup ref="popup"/>
  </view>
</template>

<script>
import page, { onPullDownRefresh, onReachBottom } from '@/mixins/page.js';
import { getReservationListAPI, deleteReservationListAPI } from '@/api/reservation.js';

export default {
  mixins: [page],
  data() {
    return {
      API: getReservationListAPI,
      listData: [],
      params: {
        pageSize: 8,
      }
    }
  },
  onLoad() {
    this.listRefresh()
  },
  onUnload() {
    uni.$off('reservation');
  },
  onPullDownRefresh,
  onReachBottom,
  methods: {
    create() {
      uni.navigateTo({
        url: './create',
        success: () => {
          uni.$once('reservation', () => {
            this.listRefresh()
          })
        }
      })
    },
    deleteReservation(item) {
      uni.showModal({
        title: '温馨提示',
        content: '确定删除该预约吗？',
        success: res => {
          if (res.confirm) {
            deleteReservationListAPI({ id: item.id }).then(() => {
              this.$refs.popup.success('删除成功');
              this.listRefresh()
            })
          }
        }
      });
    }
  }
}
</script>

<style lang="scss">
.page {
  box-sizing: border-box;
  padding: 24rpx 24rpx 28% 24rpx;
}
.block {
  background-color: #fff;
  border-radius: 14rpx;
  color: #333333;
  font-size: 26rpx;
  box-sizing: border-box;
  padding: 20rpx 24rpx;
  display: flex;
  // align-items: center;
  margin-bottom: 24rpx;
  font-weight: bold;
  position: relative;
  .yellow {
    color: #FBBF0D;
  }
}
.block__info {
  display: flex;
  flex-direction: column;
  flex: 1;
  overflow: hidden;
  .text {
    font-size: 24rpx;
    margin-top: 16rpx;
    font-weight: 400;
    line-height: 1.3;
    color: #999;
  }
}
.block__icon {
  min-width: 76rpx;
  width: 76rpx;
  height: 76rpx;
  margin-right: 20rpx;
}
.block__delete {
  width: 52rpx;
  height: 52rpx;
  position: absolute;
  top: 0;
  right: 0;
}
</style>
